package top.zhangjianyong.tools.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.zhangjianyong.tools.parm.KLineParam;
import top.zhangjianyong.tools.model.EtfDeliveryQuery;
import top.zhangjianyong.tools.service.api.ETFDateService;
import top.zhangjianyong.tools.user.VerifyUser;
import top.zhangjianyong.tools.utils.ApiResponse;

import java.util.List;

/**
 * @author ： zhangjianyong
 * @date ： 2022/9/30 10:29 AM
 */
@VerifyUser(login = false)
@RestController
@RequestMapping("/etf")
public class ETFController {

    @Autowired
    private ETFDateService etfDateService;

    /**
     * 保存基金
     */
    @PostMapping("/save/{code}")
    public ApiResponse saveETFDate(@PathVariable("code") String code) throws Exception {
        etfDateService.saveOrUpdate(code);
        return ApiResponse.success();
    }

    @PostMapping("/list")
    public ApiResponse list() {
        return etfDateService.list();
    }

    @PostMapping("/search/{code}")
    public ApiResponse search(@PathVariable("code") String code) {
        return etfDateService.search(code);
    }

    /**
     * 全部更新
     */
    @VerifyUser(login = false)
    @PostMapping("/update/all")
    public ApiResponse updateAll() throws Exception {
        return etfDateService.updateAll();
    }

    @PostMapping("/update/down3Rate")
    public ApiResponse down3Rate() throws Exception {
        return etfDateService.down3Rate();
    }

    @PostMapping("/doTimerStart")
    public ApiResponse doTimerStart() {
        return etfDateService.doTimerStart();
    }

    @PostMapping("/doTimerEnd")
    public ApiResponse doTimerEnd() {
        return etfDateService.doTimerEnd();
    }

    @PostMapping("/doTimerMonth")
    public ApiResponse doTimerMonth() {
        return etfDateService.doTimerMonth();
    }

    @PostMapping("/median")
    public ApiResponse median() {
        return etfDateService.median();
    }

    @PostMapping("/median/{unit}/{num}")
    public ApiResponse median(@PathVariable("unit") String unit,
                              @PathVariable("num") int num) {
        return etfDateService.median(unit, num);
    }

    @GetMapping("/delivery")
    public ApiResponse delivery(EtfDeliveryQuery query) {
        return etfDateService.delivery(query);
    }

    @PostMapping("/opportunity/{type}")
    public ApiResponse opportunity(@PathVariable String type) {
        return etfDateService.opportunity(type);
    }

    @PostMapping("/hold/{code}/{flag}")
    public ApiResponse hold(@PathVariable("code") String code, @PathVariable("flag") Integer flag) {
        return etfDateService.hold(code, flag);
    }

    @PostMapping("/updateNew")
    public ApiResponse updateNew() {
        return etfDateService.updateNew();
    }

    @PostMapping("/remove/{code}")
    public ApiResponse remove(@PathVariable("code") String code) {
        return etfDateService.remove(code);
    }

    @PostMapping("/list/all")
    public ApiResponse listAll() {
        return etfDateService.listAll();
    }

    @PostMapping("/kLine")
    public ApiResponse getKLine(@RequestBody List<KLineParam> params) {
        return etfDateService.getKLine(params);
    }

    @PostMapping("/getData")
    public ApiResponse getData(@RequestBody List<KLineParam> params) {
        return etfDateService.getData(params);
    }
}
